export const $msg = {
	showLoading(...arg){
		uni.showLoading(...arg);
	},
	hideLoading(...arg){
		uni.hideLoading(...arg);
	},
	showModal(...arg){
		uni.showModal(...arg);
	},
	toast(title, option){
		let argument_1_type = Object.prototype.toString.call(title).slice(8,-1);
		let argument_2_type = Object.prototype.toString.call(option).slice(8,-1);
		let callback;
		if(argument_1_type == "Object"){
			option = title;
			title = option.title;
			callback = option.callback;
		}else if(argument_2_type == "Object"){
			callback = option.callback;
		}else if(argument_2_type == "Function"){
			callback = option;
			option = {};
		}
		let json = {
		   icon: "none",
		   duration: 3000,
		   mask: false,
		   ...option,
		   title,
		   success: function() {
			  callback && setTimeout(callback, json.duration);
		   }
	   };
	   if(title.length > 7) json.icon = "none";
		uni.showToast(json);
	},
	success(title, option){
		option = option || {};
		option.icon = "success";
		this.toast(title, option)
	},
	warring(title, option){
		option = option || {}
		option.icon = "none";
		this.toast(title, option)
	},
	error(title, option){
		option = option || {}
		option.icon = "none";
		this.toast(title, option)
	},
};
export const $loading = {
   t:null,
   num:0,
   isLoading:true,
   show(options={}){
       if(this.isLoading == false) return;
       if(0 == this.num){
            clearTimeout(this.t);
            this.t = setTimeout(() => {
                $loading.hide();
                $msg.showLoading({
                   content: 'Loading...',
                   duration: 0,
				   ...options,
                })
				// this.t = setTimeout(() => {
				// 	$msg.hideLoading();
				// },30000)
            },500)
       }
       this.num++;
   },
   hide(){
       this.num--;
       if(0 >= this.num){
           clearTimeout(this.t);
		   this.num = 0;
           $msg.hideLoading();
       }
   },
};